/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <vector>
using namespace std;


int main_91()
{

    int x,P,Q,y=0,product=1;//P^0
    scanf("%d%d%d",&x,&P,&Q);
    //P to Decimal
    while (x!=0)
    {
        y+=(x%10)*product;
        x/=10;
        product*=P;
    }
    printf("%d\n",y);
    //Decimal to Q
    vector<int> z;
    do
    {
        z.push_back(y%Q);
        y/=Q;

    } while (y!=0);
    for (vector<int>::const_reverse_iterator it=z.rbegin(); it!=z.rend();++it )
    {
        printf("%d",*it);
    }
    printf("\n");
	return 0;
}
